package com.doit.day01

object _06_for循环 {
  def main(args: Array[String]): Unit = {

    val arr: Array[Int] = Array(1, 2, 3, 4, 5)

//    for (elem <- arr) {
//      // <- < -
//      println(elem)
//    }

    //序列  ==》
    val inclusive: Range.Inclusive = 1 to 10 //1 2 3 4 5 6 7 8 9 10
    val range: Range = 1 until 10  // 1 2 3 4 5 6 7 8 9

//    for (elem <- inclusive) {
//      println(elem)
//    }

    //步进
   /* for (elem <- 0 until  10 by 1) {
      println(elem)
    }

    //要求 0  to  10   我不想要5  0 1 2 3 4 6 7 8 9 10
    for (elem <- 0 until  10 by 1) {
     if(elem != 5){
       println(elem)
     }
    }

    //if(elem !=5) 循环守卫
    for (elem <- 0 until  10  if elem !=5) {
      println(elem)
    }
*/
    //我想打印 9 8 7 6 5 4 3 2 1  倒序打印
//    for (elem <- 0 until  10 reverse) {
//      println(elem)
//    }

    //双重for循环
    for(i <- 1 to 9){
      for (j <- 1 to i ){
        print(s"${i} * ${j} = ${i*j}\t")
      }
      println()
    }

    println("====================")

    for(i <- 1 to 9;j <- 1 to i){
        print(s"${i} * ${j} = ${i*j}\t")
      if(i == j ) println()
    }

    println("==============================")


    //引入变量
    for(i <- 1 to 3; j = 4 - i) {
      println("i=" + i + " j=" + j)
    }

    var j = 0
    for(i <- 1 to 3){
      j = 4 -i
      println("i=" + i + " j=" + j)
    }

  }
}
